<?php

class ReviewsController extends GxController {

    public function filters() {
        return array('rights');
    }
    
	public function actionclassReviews($id) {
         $classname= Classes::model()->findBypk($id);
          $url='/classes/admin';
        $classCourse = (!empty($classname))? 'Manage Class '.$classname->class_titile. 'Review':'';        
        $classCourseRatePostitve = count(ClassCourseTrainnerRate::model()->findAll('status=1 AND classes_id=' . $id));
        $classCourseRateNigative = count(ClassCourseTrainnerRate::model()->findAll('status=0 AND classes_id=' . $id));
        $criteria = new CDbCriteria();
        $criteria->addCondition('classes_id =' . $id);
        $statuschangeurl = Yii::app()->createUrl('reviews/statuschange/');
        $manage = 'Manage Classs';
        $dataProvider = new CActiveDataProvider('Reviews', array('criteria' => $criteria,));
        $this->render('admin', array(
            'dataProvider' => $dataProvider, 'classCourse' => $classCourse, 'manage' => $manage, 'statuschangeurl' => $statuschangeurl,
            'classCourseRateNigative' => $classCourseRateNigative, 'classCourseRatePostitve' => $classCourseRatePostitve, 'url'=> $url
        ));
    }
    
     public function actionCourseReviews($id) {
         $classname= Courses::model()->findBypk($id);
        $classCourse =  (!empty($classname))? "Manage Course ".$classname->course_titile . 'Review' :" ";
        $classCourseRatePostitve = count(ClassCourseTrainnerRate::model()->findAll('status=1 AND courses_id=' . $id));
        $classCourseRateNigative = count(ClassCourseTrainnerRate::model()->findAll('status=0 AND courses_id=' . $id));
        $url='/courses/admin';
        $criteria = new CDbCriteria();
        $criteria->addCondition('courses_id =' . $id);
        $statuschangeurl = Yii::app()->createUrl('reviews/statuschange/');
        $manage = 'Manage Course';
        $dataProvider = new CActiveDataProvider('Reviews', array('criteria' => $criteria,));
        $this->render('admin', array(
            'dataProvider' => $dataProvider, 'classCourse' => $classCourse, 'manage' => $manage, 'statuschangeurl' => $statuschangeurl,
            'classCourseRateNigative' => $classCourseRateNigative, 'classCourseRatePostitve' => $classCourseRatePostitve, 'url'=> $url
        ));
    }
    
    

    public function actionStatuschange() {
        $model = $this->loadModel($_POST['id'], 'Reviews');
        $model->status = $_POST['status'];
        $model->save();
    }

    

}